// 引入路由插件
import VueRouter from 'vue-router'
// 引入vue
import Vue from 'vue'
import routes from '@/router/routers'

// 使用插件
Vue.use(VueRouter)

const router = new VueRouter({
    routes,
    scrollBehavior(to, from, savedPosition) {
        // 始终滚动到顶部
        return { y: 0 }
    },
})

// 全局守卫：前置守卫
// router.beforeEach(async (to, from, next) => {
//     let myInfo = store.state.userInfo.userInfo

//     if (myInfo.nickname) {
//         if (to.path == '/login' || to.path == '/register') {
//             next('/home')
//         } else {
//             next()
//         }
//     } else {
//         let toPath = to.path
//         if (toPath != '/login' && toPath != '/register') {
//             next('/login?redirect=' + toPath)
//         } else {
//             next()
//         }
//     }
// })

export default router

